package com.sh.threadmethod.threadstatus;

/**
 * @Auther: sh
 * @Version 1.0
 * @Description:
 */
public class LookThreadStatus implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        LookThreadStatus lookThreadStatus = new LookThreadStatus();
        Thread thread = new Thread(lookThreadStatus);

        Thread.State state = thread.getState();
        System.out.println(state);  // NEW


        thread.start();
        state = thread.getState();
        System.out.println(state);   // RUNNABLE

        while (state != Thread.State.TERMINATED) {
            Thread.sleep(100);
            state = thread.getState();
            System.out.println(state);
        }
    }
}

